 /* 需求描述：给定任意日期作为入职日期，工作N个工作日之后，计算离职日期？ 
		 注：“工作日”为周一至周五，不包含周六、日。
		      “首个工作日”从注册日期之后算起，即不包含注册日期在内。
		      “离职日期”为最后一个工作日的后一天。
		       如：     入职日期：2010/8/1     工作天数：10     
		       离职日期：2010/8/14 */   
   // 入职日期 
   //var entryDate = ParseDate("2013/1/28"); 
   // 工作天数 
   //var workingDays = 1; 
   // 离职日期 
   //var departureDate = GetDepartureDate(entryDate, workingDays);   
   //document.write(GetDateString(departureDate));   
   function GetDepartureDate(entryDate, workingDays) {    
   		// 每周工作天数。     
   		var workingDaysPerWeek = 5;    
   		 // 离职日期     
   		 var departureDate = null;     
   		 // 首个工作日     
   		 var firstWorkingDate = GetFirstWokingDate(entryDate);     
   		 // 周末跨度数     
   		 var weekendSpan = 0;     
   		 // 第一周工作天数。     
   		 var firstWeekWorkingDays = 0;     
   		 // 最后一周工作天数。     
   		 var lastWeekWorkingDays = 0;     
   		 // 从首个工作日之后，到离职日期之间持续的天数（包括离职日期在内）。     
       		 var continuedDaysAfterFirstWorkingDate = 0;       
       		 if (IsMonday(firstWorkingDate)) { 
       		 	        continuedDaysAfterFirstWorkingDate = GetContinuedDays(workingDays, workingDaysPerWeek, weekendSpan);     
       		 } else { 
       		 	        firstWeekWorkingDays = workingDaysPerWeek - firstWorkingDate.getDay() + 1;        
       		 	         if (firstWeekWorkingDays >= workingDays) {
       		 	         	             continuedDaysAfterFirstWorkingDate = workingDays; 
       		 	          } else { 
       		 	          	            weekendSpan += 1;
       		 	          	            workingDays -= firstWeekWorkingDays;             
       		 	          	            continuedDaysAfterFirstWorkingDate = firstWeekWorkingDays + GetContinuedDays(workingDays, workingDaysPerWeek, weekendSpan);        
       		 	          }     
       		 }     
       		 departureDate = GetDateAfterGivenDate(firstWorkingDate, continuedDaysAfterFirstWorkingDate); 
       		 return departureDate;
	 } 
	
	function ParseDate(yyyyMMddString) {
		     return new Date(Date.parse(yyyyMMddString)); 
   } 
   
   function GetFirstWokingDate(entryDate) {
   	     var firstWorkingDate = GetNextDate(entryDate);       
   	     while (!IsWorkingDate(firstWorkingDate)) {        
   	     		 firstWorkingDate = GetNextDate(firstWorkingDate);     
   	     }     
   	     return firstWorkingDate; 
   } 
   
   function IsWorkingDate(givenDate) {
   	     var givenWeekday = givenDate.getDay();    
   	      return (givenWeekday >= 1 && givenWeekday <= 5) 
   }
  
   function GetNextDate(givenDate) {
   	     var millisecondsPerDay = 86400000;     
   	     return new Date(givenDate.valueOf() + millisecondsPerDay); 
   } 
   
   function GetDateString(givenDate) {     
	   	var dateString = "";     
   	dateString += givenDate.getYear() + "-";     
   	dateString += (givenDate.getMonth() + 1) + "-";     
	   	dateString += givenDate.getDate(); 
	   	return dateString; 
   	} 
   
   	function IsMonday(givenDate) {
   		     return givenDate.getDay() == 1; 
    }
    
    function GetDateAfterGivenDate(givenDate, continuedDays) {
    	     var millisecondsPerDay = 86400000;     
    	     return new Date(givenDate.valueOf() + (millisecondsPerDay * continuedDays)); 
    } 
    
    function GetContinuedDays(workingDays, workingDaysPerWeek, weekendSpan) {
    	     // 周末天数。     
    	     var daysPerWeekend = 2;     
    	     weekendSpan += Math.floor(workingDays / workingDaysPerWeek);     
    	     var lastWeekWorkingDays = workingDays % workingDaysPerWeek;     
    	     if (lastWeekWorkingDays == 0) {
    	     	         weekendSpan -= 1;     
    	     }     
    	     return (workingDays + (daysPerWeekend * weekendSpan));
   } 